class Solution
{
public:
    int minNumberOfFrogs(string croakOfFrogs)
    {
        unordered_map<char, int> count;
        int minCroak = 0;
        for (char c : croakOfFrogs)
        {
            switch (c)
            {
            case 'c':
                ++count['c'];
                minCroak = max(minCroak, count['c']);
                break;
            case 'r':
                if (count['c'] > count['r'])
                {
                    ++count['r'];
                }
                else
                {
                    return -1;
                }
                break;
            case 'o':
                if (count['r'] > count['o'])
                {
                    ++count['o'];
                }
                else
                {
                    return -1;
                }
                break;
            case 'a':
                if (count['o'] > count['a'])
                {
                    ++count['a'];
                }
                else
                {
                    return -1;
                }
                break;
            case 'k':
                if (count['a'] > 0)
                {
                    --count['c'];
                    --count['r'];
                    --count['o'];
                    --count['a'];
                }
                else
                {
                    return -1;
                }
                break;
            }
        }
        if (count['c'] != 0)
        {
            return -1;
        }

        return minCroak;
    }
};